package com.jjx.controller;

import com.github.pagehelper.PageInfo;
import com.jjx.domain.Department;
import com.jjx.domain.Result;
import com.jjx.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dep")
public class DepartmentController {

    @Autowired
    private IDepartmentService iDepartmentService;

    @GetMapping("findAll")
    public Result findAll(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,@RequestParam(name = "limit",required = false,defaultValue = "100")Integer limit,Department department) {
        List<Department> all = iDepartmentService.findAll(page,limit,department);
        PageInfo<Department> pageInfo = new PageInfo<>(all);
        Result rs = new Result();
        rs.setCode(0);
        rs.setData(all);
        return rs;
    }

    @GetMapping("findAllDep")
    public Result findAllDep(@RequestParam(name = "id",required = false,defaultValue = "0") int id) {
        List<Department> all = iDepartmentService.findAllDep(id);
        Result rs = new Result();
        rs.setData(all);
        return rs;
    }

    @GetMapping("save")
    public Result save(Department department) {
        iDepartmentService.save(department);
        Result rs = new Result();
        return rs;
    }

    @GetMapping("del")
    public Result del(int[] id) {
        iDepartmentService.delete(id);
        Result rs = new Result();
        return rs;
    }

    @GetMapping("upd")
    public Result upd(Department department) {
        iDepartmentService.update(department);
        Result rs = new Result();
        return rs;
    }

    @GetMapping("findChildren")
    public List<Department> findChildren(Integer id) {
        List<Department> children = iDepartmentService.findChildren(id);
        return children;
    }
}
